package com.blockmeta.bbs.businesslibrary.umeng.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.blockmeta.bbs.businesslibrary.R;
import com.blockmeta.bbs.businesslibrary.umeng.AnimatorUtil;
import com.blockmeta.bbs.businesslibrary.umeng.BaseShareDialog;
import com.blockmeta.bbs.businesslibrary.umeng.MEDIA_TYPE;
import com.blockmeta.bbs.businesslibrary.umeng.ScreenShotUtil;
import com.blockmeta.bbs.businesslibrary.umeng.ShareResTask;
import com.blockmeta.bbs.businesslibrary.umeng.ShareRouter;
import com.blockmeta.bbs.businesslibrary.umeng.SharedUtils;

/**
 * @author AirThor
 * @date 2020/3/25.
 * 此处弹出链专题和学院专题分享dialog
 */
public class ChainAndCollegeShare extends BaseShareDialog {
    private View mShareView;

    public ChainAndCollegeShare(Context context, ShareRouter shareRouter) {
        super(context, shareRouter);
    }

    @Override
    protected void initContent() {
        ImageView wechat = find(R.id.iv_wechat);
        ImageView ciecle =  find(R.id.iv_wechat_circle);
        ImageView pic =  find(R.id.iv_long_pic);
        ImageView qq =  find(R.id.iv_qq);
        ImageView weibo =  find(R.id.iv_weibo);
        TextView dismiss =  find(R.id.tv_dismiss);
        mShareView = find(R.id.scroll_share_image);
        ImageView imageView=find(R.id.share_iv_college_chain);
        imageView.setImageBitmap(mShareRouter.getDisplayBitmap());

        View shareBoard = find(R.id.v_share_bg);
        AnimatorUtil.bottomToTopAnim(shareBoard,500,false,0f);
        AnimatorUtil.bottomToTopAnim(wechat,1100,1f);
        AnimatorUtil.bottomToTopAnim(ciecle,1000,1f);
        AnimatorUtil.bottomToTopAnim(weibo,900,1f);
        AnimatorUtil.bottomToTopAnim(qq,800,1f);
        AnimatorUtil.bottomToTopAnim(pic,700,1f);

        wechat.setOnClickListener(this);
        ciecle.setOnClickListener(this);
        pic.setOnClickListener(this);
        qq.setOnClickListener(this);
        weibo.setOnClickListener(this);
        dismiss.setOnClickListener(this);
    }

    @Override
    protected int setContentViews() {
        return R.layout.view_share_college_chain;
    }

    @Override
    protected void setAttributes() {
        setAttribute(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT, Gravity.CENTER);
    }

    @Override
    protected void startShare(final MEDIA_TYPE mediaType) {
        ShareResTask.doTask(new ShareResTask.NormalBitmapTask(mShareView) {
            @Override
            public void doOnUIThread(Bitmap bitmap) {
                share(bitmap,mediaType);
                safeDismiss();
            }
        });
    }

    private void share(Bitmap bitmap, MEDIA_TYPE mediaType) {
        ScreenShotUtil.zoomImg(bitmap, 1080);
        if (mediaType == MEDIA_TYPE.SAVE){
            ShareResTask.doTask(new ShareResTask.SaveImgTask(mShareRouter.getContext(),bitmap));
        }else {
            SharedUtils.sharePic((Activity) mShareRouter.getContext(),mediaType.mMedia,bitmap,mShareRouter.getUMShareListener());
        }
    }
}
